package hibernate.billStream;

import java.util.Date;
import java.util.StringTokenizer;

import hibernate.p.Depositer;
import hibernate.p.Pair;
import hibernate.p.Unit;
import hibernate.administratorAccount.FrontDesk;
import hibernate.clientAccount.SingleClient;

public class Bill {
	
	private Long id;
	private Pair price=new Pair();
	private BillState billState;
	private MergedBill group;
	private FrontDesk operator;
	private Date timeCreate,timePay;
	private String billNumber;
	
	public Date getTimePay(){
		return timePay;
	}
	
	public void setTimePay(Date pay){
		this.timePay=pay;
	}
	
	//one of these two is null
	private CorporationEntity currentCorporationDeposite;
	private SingleClient currentClientDeposite;
	
	public SingleClient getCurrentClientDeposite(){
		return this.currentClientDeposite;
	}
	
	public CorporationEntity getCurrentCorporationDeposite(){
		return this.currentCorporationDeposite;
	}
	
	public void setCurrentClientDeposite(SingleClient client){
		this.currentClientDeposite=client;
	}
	
	public void setCurrentCorporationDeposite(CorporationEntity entity){
		this.currentCorporationDeposite=entity;
	}
	
	public void setBillNumber(String str){
		this.billNumber=str;
	}
	
	public String getBillNumber(){
		return billNumber == null ? "" : billNumber;
	}
	
	public void setTimeCreate(Date dat){
		this.timeCreate=dat;
	}
	
	public Date getTimeCreate(){
		return timeCreate;
	}
	
	public void setOperator(FrontDesk fd){this.operator=fd;}
	
	public FrontDesk getOperator(){return operator;}
	
	public void setGroup(MergedBill bill){this.group=bill;}
	
	public MergedBill getGroup(){return group;}
	
	public void setId(Long id){
		this.id=id;
	}
	
	public Long getId(){
		return id;
	}
	
	public Double getPrice(){
		return ((Double)price.getFirst()).doubleValue();
	}
	
	public void setPrice(Double info){
		this.price.setFirst(info);
	}
	
	public Unit getPriceUnit(){
		return ((Unit)this.price.getSecond());
	}
	
	public void setPriceUnit(String unit){
		this.price.setSecond(Unit.parseUnit(unit));
	}
	
	public void setBillState(String state){
		if(state=="PAYED")
			billState=BillState.getPayed();
		else if(state=="BAD")
			billState=BillState.getBad();
		else if(state=="ACTIVE")
			billState=BillState.getActive();
		else if(state=="UNSETTLED")
			billState=BillState.getUnsettled();
		else if(state=="UPBIDING")
			billState=BillState.getUpBiding();
		else
			throw new java.lang.IllegalArgumentException("no this BillState");
	}
	
	public String getBillState(){
		return billState.toString();
	}
	
	public boolean equals(Object obj){
		if(!(obj instanceof Bill))
			return false;
		else return this.id.equals(((Bill)obj).id);
	}
	
	public String toString(){
		return "bill: "+this.id.toString();
	}
}
